﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using ZLDC.Common.Estate;

namespace ZLDC.DAL.Estate
{
    public class TranLogDAL
    {
                                                                                                                        public static void p_tran_log_insert(int user_id, string user_name, int user_from, string user_from_name, int user_to, string user_to_name, string opr_type, string sqlText, out string outmsg, out int newid, _Database db)
        {
            List<SqlParameter> parms = new List<SqlParameter>();

            parms.Add(new SqlParameter("@user_id", user_id));
            parms.Add(new SqlParameter("@user_name", user_name));
            parms.Add(new SqlParameter("@user_from", user_from));
            parms.Add(new SqlParameter("@user_from_name", user_from_name));
            parms.Add(new SqlParameter("@user_to", user_to));
            parms.Add(new SqlParameter("@user_to_name", user_to_name));
            parms.Add(new SqlParameter("@opr_type", opr_type));
            parms.Add(new SqlParameter("@sqlText", sqlText));

            SqlParameter pOutmsg = new SqlParameter("@outmsg", SqlDbType.VarChar, 256);
            pOutmsg.Direction = ParameterDirection.Output;
            parms.Add(pOutmsg);

            SqlParameter pNewid = new SqlParameter("@newid", SqlDbType.Int, 4);
            pNewid.Direction = ParameterDirection.Output;
            parms.Add(pNewid);

            db.execute_procedure("p_tran_log_insert", parms);

            outmsg = (pOutmsg.Value == System.DBNull.Value) ? "" : Convert.ToString(pOutmsg.Value);
            newid = (pNewid.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pNewid.Value);

        }
                                                                                public static DataTable p_tran_log_list_table(int page, int pagesize, string condition, ref int total, _Database db)
        {
            List<SqlParameter> parms = new List<SqlParameter>();

            parms.Add(new SqlParameter("@page", page));
            parms.Add(new SqlParameter("@pagesize", pagesize));
            parms.Add(new SqlParameter("@condition", condition));

            SqlParameter pTotal = new SqlParameter("@total", SqlDbType.Int, 4);
            pTotal.Direction = ParameterDirection.InputOutput;
            pTotal.Value = total;
            parms.Add(pTotal);
            SqlParameter pRetval = new SqlParameter("@retval", SqlDbType.Int, 4);
            pRetval.Direction = ParameterDirection.ReturnValue;
            parms.Add(pRetval);

            DataTable dt = null;
            dt = db.GetDataTable("p_tran_log_list", parms);

            total = (pTotal.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pTotal.Value);

            int retval = (pRetval.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pRetval.Value);

            return dt;
        }
    }
}
